package com.f6.common.service;

import net.sf.json.JSONObject;

import com.f6.common.util.JsonUtil;

public class WxbService {

	public static JSONObject savePemployeeById(String employeeId,String msgAppId,String msgOpenId){
		String url = "http://api.f6car.com/datasrv/2.0/wxb/savePemployeeById";
		String param = "{\"businessCode\": \"f60025\", \"params\": "
				+ "{\"employeeId\":\""+employeeId+"\",\"msgAppId\":\""+msgAppId+"\",\"msgOpenId\":\""+msgOpenId+"\"}}";
		
		// 需要提交的json数据
		// 创建永久带参二维码
		JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParamPost(url,param);
		return jsonObject;
	}
	
	public static void saveUserOpenId(String userId, String f6OpenId){
		String url = "http://api.f6car.com/datasrv/2.0/wxb/updatePuser";
		String param = "{\"businessCode\": \"f60016\", \"params\": "
				+ "{\"userId\":\""+userId+"\",\"f6OpenId\":\""+f6OpenId+"\"}}";
		
		// 需要提交的json数据
		// 创建永久带参二维码
		JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParamPost(url,param);
	}
	
	public static String getScribeReply(String wxAppId){
		String url = "http://api.f6car.com/datasrv/2.0/wxb/getScribeAutoReply?";
		String scribeReply = "";
		String param = "param={\"businessCode\": \"f60029\", \"params\": "
				+ "{\"wxAppId\":\""+wxAppId+"\"}}";
		url += param;
		JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParam(url);
		if(jsonObject != null && !jsonObject.isNullObject()){
			String result = null;
    		try{
    			result = jsonObject.getString("result");
    		}catch(Exception ex){
    			result = null;
    		}
    		if(result != null &&  result.equals("0000")){
    			try{
    				scribeReply = jsonObject.getString("detail");
				}catch(Exception ex){
					//do nothing
					scribeReply = "";
				}
    		}
		}
		return scribeReply;
	}
	
	public static String getAutoReply(String wxAppId){
		String url = "http://api.f6car.com/datasrv/2.0/wxb/getAutoReply?";
		String autoReply = "";
		String param = "param={\"businessCode\": \"f60030\", \"params\": "
				+ "{\"wxAppId\":\""+wxAppId+"\"}}";
		url += param;
		JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParam(url);
		if(jsonObject != null && !jsonObject.isNullObject()){
			String result = null;
    		try{
    			result = jsonObject.getString("result");
    		}catch(Exception ex){
    			result = null;
    		}
    		if(result != null &&  result.equals("0000")){
    			try{
    				autoReply = jsonObject.getString("detail");
				}catch(Exception ex){
					//do nothing
					autoReply = "";
				}
    		}
		}
		return autoReply;
	}
	
	public static String getKeyAutoReply(String wxAppId,String keyword){
		String url = "http://api.f6car.com/datasrv/2.0/wxb/getKeyAutoReply?";
		String keyAutoReply = "";
		String param = "param={\"businessCode\": \"f60031\", \"params\": "
				+ "{\"wxAppId\":\""+wxAppId+"\",\"keyword\":\""+keyword+"\"}}";
		url += param;
		JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParam(url);
		if(jsonObject != null && !jsonObject.isNullObject()){
			String result = null;
    		try{
    			result = jsonObject.getString("result");
    		}catch(Exception ex){
    			result = null;
    		}
    		if(result != null &&  result.equals("0000")){
    			try{
    				keyAutoReply = jsonObject.getString("detail");
				}catch(Exception ex){
					//do nothing
					keyAutoReply = "";
				}
    		}
		}
		return keyAutoReply;
	}
	
	
	public static String deletePuser(String openId){
		String url = "http://api.f6car.com/datasrv/2.0/wxb/deletePuser?";
		String keyAutoReply = "";
		String param = "param={\"businessCode\": \"f60038\", \"params\": "
				+ "{\"wxOpenId\":\""+openId+"\"}}";
		url += param;
		JSONObject jsonObject = JsonUtil.resolvejsonFromUrlForParam(url);
		if(jsonObject != null && !jsonObject.isNullObject()){
			String result = null;
    		try{
    			result = jsonObject.getString("result");
    		}catch(Exception ex){
    			result = null;
    		}
    		if(result != null &&  result.equals("0000")){
    			try{
    				keyAutoReply = jsonObject.getString("detail");
				}catch(Exception ex){
					//do nothing
					keyAutoReply = "";
				}
    		}
		}
		return keyAutoReply;
	}
}
